﻿/// <reference path="../Scripts/msls-1.0.0.js" />

window.myapp = msls.application;

(function (lightSwitchApplication) {

    var $Entity = msls.Entity,
        $DataService = msls.DataService,
        $DataWorkspace = msls.DataWorkspace,
        $defineEntity = msls._defineEntity,
        $defineDataService = msls._defineDataService,
        $defineDataWorkspace = msls._defineDataWorkspace,
        $DataServiceQuery = msls.DataServiceQuery,
        $toODataString = msls._toODataString;

    function Contact(entitySet) {
        /// <summary>
        /// Represents the Contact entity type.
        /// </summary>
        /// <param name="entitySet" type="msls.EntitySet" optional="true">
        /// The entity set that should contain this contact.
        /// </param>
        /// <field name="Id" type="Number">
        /// Gets or sets the id for this contact.
        /// </field>
        /// <field name="RowVersion" type="Array">
        /// Gets or sets the rowVersion for this contact.
        /// </field>
        /// <field name="ContactName" type="String">
        /// Gets or sets the contactName for this contact.
        /// </field>
        /// <field name="ContactCompany" type="String">
        /// Gets or sets the contactCompany for this contact.
        /// </field>
        /// <field name="ContactPhone" type="String">
        /// Gets or sets the contactPhone for this contact.
        /// </field>
        /// <field name="ContactEmail" type="String">
        /// Gets or sets the contactEmail for this contact.
        /// </field>
        /// <field name="ContactType" type="Number">
        /// Gets or sets the contactType for this contact.
        /// </field>
        /// <field name="ContactState" type="String">
        /// Gets or sets the contactState for this contact.
        /// </field>
        /// <field name="Customer" type="Customer">
        /// Gets or sets the customer for this contact.
        /// </field>
        /// <field name="details" type="msls.application.Contact.Details">
        /// Gets the details for this contact.
        /// </field>
        $Entity.call(this, entitySet);
    }

    function Customer(entitySet) {
        /// <summary>
        /// Represents the Customer entity type.
        /// </summary>
        /// <param name="entitySet" type="msls.EntitySet" optional="true">
        /// The entity set that should contain this customer.
        /// </param>
        /// <field name="CustomerID" type="String">
        /// Gets or sets the customerID for this customer.
        /// </field>
        /// <field name="CompanyName" type="String">
        /// Gets or sets the companyName for this customer.
        /// </field>
        /// <field name="ContactName" type="String">
        /// This is our primary contact at this company.
        /// </field>
        /// <field name="ContactTitle" type="String">
        /// Gets or sets the contactTitle for this customer.
        /// </field>
        /// <field name="Address" type="String">
        /// Gets or sets the address for this customer.
        /// </field>
        /// <field name="City" type="String">
        /// Gets or sets the city for this customer.
        /// </field>
        /// <field name="Region" type="String">
        /// Gets or sets the region for this customer.
        /// </field>
        /// <field name="PostalCode" type="String">
        /// Gets or sets the postalCode for this customer.
        /// </field>
        /// <field name="Country" type="String">
        /// Gets or sets the country for this customer.
        /// </field>
        /// <field name="Phone" type="String">
        /// Gets or sets the phone for this customer.
        /// </field>
        /// <field name="Fax" type="String">
        /// Gets or sets the fax for this customer.
        /// </field>
        /// <field name="Orders" type="msls.EntityCollection" elementType="msls.application.Order">
        /// Gets the orders for this customer.
        /// </field>
        /// <field name="Contact" type="Contact">
        /// Gets or sets the contact for this customer.
        /// </field>
        /// <field name="details" type="msls.application.Customer.Details">
        /// Gets the details for this customer.
        /// </field>
        $Entity.call(this, entitySet);
    }

    function Order_Detail(entitySet) {
        /// <summary>
        /// Represents the Order_Detail entity type.
        /// </summary>
        /// <param name="entitySet" type="msls.EntitySet" optional="true">
        /// The entity set that should contain this order_Detail.
        /// </param>
        /// <field name="OrderID" type="Number">
        /// Gets or sets the orderID for this order_Detail.
        /// </field>
        /// <field name="ProductID" type="Number">
        /// Gets or sets the productID for this order_Detail.
        /// </field>
        /// <field name="UnitPrice" type="Number">
        /// Gets or sets the unitPrice for this order_Detail.
        /// </field>
        /// <field name="Quantity" type="Number">
        /// Gets or sets the quantity for this order_Detail.
        /// </field>
        /// <field name="Discount" type="Number">
        /// Gets or sets the discount for this order_Detail.
        /// </field>
        /// <field name="Order" type="msls.application.Order">
        /// Gets or sets the order for this order_Detail.
        /// </field>
        /// <field name="Product" type="msls.application.Product">
        /// Gets or sets the product for this order_Detail.
        /// </field>
        /// <field name="details" type="msls.application.Order_Detail.Details">
        /// Gets the details for this order_Detail.
        /// </field>
        $Entity.call(this, entitySet);
    }

    function Order(entitySet) {
        /// <summary>
        /// Represents the Order entity type.
        /// </summary>
        /// <param name="entitySet" type="msls.EntitySet" optional="true">
        /// The entity set that should contain this order.
        /// </param>
        /// <field name="OrderID" type="Number">
        /// Gets or sets the orderID for this order.
        /// </field>
        /// <field name="EmployeeID" type="Number">
        /// Gets or sets the employeeID for this order.
        /// </field>
        /// <field name="OrderDate" type="Date">
        /// Gets or sets the orderDate for this order.
        /// </field>
        /// <field name="RequiredDate" type="Date">
        /// Gets or sets the requiredDate for this order.
        /// </field>
        /// <field name="ShippedDate" type="Date">
        /// Gets or sets the shippedDate for this order.
        /// </field>
        /// <field name="ShipVia" type="Number">
        /// Gets or sets the shipVia for this order.
        /// </field>
        /// <field name="Freight" type="Number">
        /// Gets or sets the freight for this order.
        /// </field>
        /// <field name="ShipName" type="String">
        /// Gets or sets the shipName for this order.
        /// </field>
        /// <field name="ShipAddress" type="String">
        /// Gets or sets the shipAddress for this order.
        /// </field>
        /// <field name="ShipCity" type="String">
        /// Gets or sets the shipCity for this order.
        /// </field>
        /// <field name="ShipRegion" type="String">
        /// Gets or sets the shipRegion for this order.
        /// </field>
        /// <field name="ShipPostalCode" type="String">
        /// Gets or sets the shipPostalCode for this order.
        /// </field>
        /// <field name="ShipCountry" type="String">
        /// Gets or sets the shipCountry for this order.
        /// </field>
        /// <field name="Customer" type="msls.application.Customer">
        /// Gets or sets the customer for this order.
        /// </field>
        /// <field name="Order_Details" type="msls.EntityCollection" elementType="msls.application.Order_Detail">
        /// Gets the order_Details for this order.
        /// </field>
        /// <field name="details" type="msls.application.Order.Details">
        /// Gets the details for this order.
        /// </field>
        $Entity.call(this, entitySet);
    }

    function Product(entitySet) {
        /// <summary>
        /// Represents the Product entity type.
        /// </summary>
        /// <param name="entitySet" type="msls.EntitySet" optional="true">
        /// The entity set that should contain this product.
        /// </param>
        /// <field name="ProductID" type="Number">
        /// Gets or sets the productID for this product.
        /// </field>
        /// <field name="ProductName" type="String">
        /// Gets or sets the productName for this product.
        /// </field>
        /// <field name="SupplierID" type="Number">
        /// Gets or sets the supplierID for this product.
        /// </field>
        /// <field name="CategoryID" type="Number">
        /// Gets or sets the categoryID for this product.
        /// </field>
        /// <field name="QuantityPerUnit" type="String">
        /// Gets or sets the quantityPerUnit for this product.
        /// </field>
        /// <field name="UnitPrice" type="Number">
        /// Gets or sets the unitPrice for this product.
        /// </field>
        /// <field name="UnitsInStock" type="Number">
        /// Gets or sets the unitsInStock for this product.
        /// </field>
        /// <field name="UnitsOnOrder" type="Number">
        /// Gets or sets the unitsOnOrder for this product.
        /// </field>
        /// <field name="ReorderLevel" type="Number">
        /// Gets or sets the reorderLevel for this product.
        /// </field>
        /// <field name="Discontinued" type="Boolean">
        /// Gets or sets the discontinued for this product.
        /// </field>
        /// <field name="Order_Details" type="msls.EntityCollection" elementType="msls.application.Order_Detail">
        /// Gets the order_Details for this product.
        /// </field>
        /// <field name="details" type="msls.application.Product.Details">
        /// Gets the details for this product.
        /// </field>
        $Entity.call(this, entitySet);
    }

    function ApplicationData(dataWorkspace) {
        /// <summary>
        /// Represents the ApplicationData data service.
        /// </summary>
        /// <param name="dataWorkspace" type="msls.DataWorkspace">
        /// The data workspace that created this data service.
        /// </param>
        /// <field name="Contacts" type="msls.EntitySet">
        /// Gets the Contacts entity set.
        /// </field>
        /// <field name="details" type="msls.application.ApplicationData.Details">
        /// Gets the details for this data service.
        /// </field>
        $DataService.call(this, dataWorkspace);
    };

    function NorthwindEntitiesData(dataWorkspace) {
        /// <summary>
        /// Represents the NorthwindEntitiesData data service.
        /// </summary>
        /// <param name="dataWorkspace" type="msls.DataWorkspace">
        /// The data workspace that created this data service.
        /// </param>
        /// <field name="Customers" type="msls.EntitySet">
        /// Gets the Customers entity set.
        /// </field>
        /// <field name="Order_Details" type="msls.EntitySet">
        /// Gets the Order_Details entity set.
        /// </field>
        /// <field name="Orders" type="msls.EntitySet">
        /// Gets the Orders entity set.
        /// </field>
        /// <field name="Products" type="msls.EntitySet">
        /// Gets the Products entity set.
        /// </field>
        /// <field name="details" type="msls.application.NorthwindEntitiesData.Details">
        /// Gets the details for this data service.
        /// </field>
        $DataService.call(this, dataWorkspace);
    };
    function DataWorkspace() {
        /// <summary>
        /// Represents the data workspace.
        /// </summary>
        /// <field name="ApplicationData" type="msls.application.ApplicationData">
        /// Gets the ApplicationData data service.
        /// </field>
        /// <field name="NorthwindEntitiesData" type="msls.application.NorthwindEntitiesData">
        /// Gets the NorthwindEntitiesData data service.
        /// </field>
        /// <field name="details" type="msls.application.DataWorkspace.Details">
        /// Gets the details for this data workspace.
        /// </field>
        $DataWorkspace.call(this);
    };

    msls._addToNamespace("msls.application", {

        Contact: $defineEntity(Contact, [
            { name: "Id", type: Number },
            { name: "RowVersion", type: Array },
            { name: "ContactName", type: String },
            { name: "ContactCompany", type: String },
            { name: "ContactPhone", type: String },
            { name: "ContactEmail", type: String },
            { name: "ContactType", type: Number },
            { name: "ContactState", type: String },
            { name: "Customer", kind: "virtualReference", type: Customer }
        ]),

        Customer: $defineEntity(Customer, [
            { name: "CustomerID", type: String },
            { name: "CompanyName", type: String },
            { name: "ContactName", type: String },
            { name: "ContactTitle", type: String },
            { name: "Address", type: String },
            { name: "City", type: String },
            { name: "Region", type: String },
            { name: "PostalCode", type: String },
            { name: "Country", type: String },
            { name: "Phone", type: String },
            { name: "Fax", type: String },
            { name: "Orders", kind: "collection", elementType: Order },
            { name: "Contact", kind: "virtualReference", type: Contact }
        ]),

        Order_Detail: $defineEntity(Order_Detail, [
            { name: "OrderID", type: Number },
            { name: "ProductID", type: Number },
            { name: "UnitPrice", type: Number },
            { name: "Quantity", type: Number },
            { name: "Discount", type: Number },
            { name: "Order", kind: "reference", type: Order },
            { name: "Product", kind: "reference", type: Product }
        ]),

        Order: $defineEntity(Order, [
            { name: "OrderID", type: Number },
            { name: "EmployeeID", type: Number },
            { name: "OrderDate", type: Date },
            { name: "RequiredDate", type: Date },
            { name: "ShippedDate", type: Date },
            { name: "ShipVia", type: Number },
            { name: "Freight", type: Number },
            { name: "ShipName", type: String },
            { name: "ShipAddress", type: String },
            { name: "ShipCity", type: String },
            { name: "ShipRegion", type: String },
            { name: "ShipPostalCode", type: String },
            { name: "ShipCountry", type: String },
            { name: "Customer", kind: "reference", type: Customer },
            { name: "Order_Details", kind: "collection", elementType: Order_Detail }
        ]),

        Product: $defineEntity(Product, [
            { name: "ProductID", type: Number },
            { name: "ProductName", type: String },
            { name: "SupplierID", type: Number },
            { name: "CategoryID", type: Number },
            { name: "QuantityPerUnit", type: String },
            { name: "UnitPrice", type: Number },
            { name: "UnitsInStock", type: Number },
            { name: "UnitsOnOrder", type: Number },
            { name: "ReorderLevel", type: Number },
            { name: "Discontinued", type: Boolean },
            { name: "Order_Details", kind: "collection", elementType: Order_Detail }
        ]),

        ApplicationData: $defineDataService(ApplicationData, lightSwitchApplication.rootUri + "/ApplicationData.svc", [
            { name: "Contacts", elementType: Contact }
        ], [
            {
                name: "Contacts_SingleOrDefault", value: function (Id) {
                    return new $DataServiceQuery({ _entitySet: this.Contacts },
                        lightSwitchApplication.rootUri + "/ApplicationData.svc" + "/Contacts(" + "Id=" + $toODataString(Id, "Int32?") + ")"
                    );
                }
            }
        ]),

        NorthwindEntitiesData: $defineDataService(NorthwindEntitiesData, lightSwitchApplication.rootUri + "/NorthwindEntitiesData.svc", [
            { name: "Customers", elementType: Customer },
            { name: "Order_Details", elementType: Order_Detail },
            { name: "Orders", elementType: Order },
            { name: "Products", elementType: Product }
        ], [
            {
                name: "Customers_SingleOrDefault", value: function (CustomerID) {
                    return new $DataServiceQuery({ _entitySet: this.Customers },
                        lightSwitchApplication.rootUri + "/NorthwindEntitiesData.svc" + "/Customers(" + "CustomerID=" + $toODataString(CustomerID, "String?") + ")"
                    );
                }
            },
            {
                name: "Order_Details_SingleOrDefault", value: function (OrderID, ProductID) {
                    return new $DataServiceQuery({ _entitySet: this.Order_Details },
                        lightSwitchApplication.rootUri + "/NorthwindEntitiesData.svc" + "/Order_Details(" + "OrderID=" + $toODataString(OrderID, "Int32?") + "," + "ProductID=" + $toODataString(ProductID, "Int32?") + ")"
                    );
                }
            },
            {
                name: "Orders_SingleOrDefault", value: function (OrderID) {
                    return new $DataServiceQuery({ _entitySet: this.Orders },
                        lightSwitchApplication.rootUri + "/NorthwindEntitiesData.svc" + "/Orders(" + "OrderID=" + $toODataString(OrderID, "Int32?") + ")"
                    );
                }
            },
            {
                name: "Products_SingleOrDefault", value: function (ProductID) {
                    return new $DataServiceQuery({ _entitySet: this.Products },
                        lightSwitchApplication.rootUri + "/NorthwindEntitiesData.svc" + "/Products(" + "ProductID=" + $toODataString(ProductID, "Int32?") + ")"
                    );
                }
            },
            {
                name: "CurrentProducts", value: function () {
                    return new $DataServiceQuery({ _entitySet: this.Products },
                        lightSwitchApplication.rootUri + "/NorthwindEntitiesData.svc" + "/CurrentProducts()",
                        {
                        });
                }
            },
            {
                name: "ProductsByCategory", value: function (CategoryID) {
                    return new $DataServiceQuery({ _entitySet: this.Products },
                        lightSwitchApplication.rootUri + "/NorthwindEntitiesData.svc" + "/ProductsByCategory()",
                        {
                            CategoryID: $toODataString(CategoryID, "Int32?")
                        });
                }
            },
            {
                name: "MatchCustomer", value: function (ContactName) {
                    return new $DataServiceQuery({ _entitySet: this.Customers },
                        lightSwitchApplication.rootUri + "/NorthwindEntitiesData.svc" + "/MatchCustomer()",
                        {
                            ContactName: $toODataString(ContactName, "String?")
                        });
                }
            }
        ]),

        DataWorkspace: $defineDataWorkspace(DataWorkspace, [
            { name: "ApplicationData", type: ApplicationData },
            { name: "NorthwindEntitiesData", type: NorthwindEntitiesData }
        ])

    });

}(msls.application));
